<link rel="stylesheet" type="text/css" href="<?= $base_url ?>css/fmis/faculty/search.css">

<div class="faculty">
    <div class="search">
        <div class="container-fluid">
            <legend><h1>Search Faculty</h1></legend>
            <div class="col-lg-12 container-fluid">
                <div class="col-lg-3">
                    <!--<form class="form-search"> -->
                    <?php echo form_open('fmis/faculty/search', array('class' => 'form-search')); ?>
                    <div class="search-filter-group">
                        <p>
                            <input type="checkbox" id="cb_name_filter" name="cb_name_filter" value="name_filter" <?php if($cb_name) echo 'checked';?>>  Search by Name<br/>
                            <input type="text" id="name_filter" name="name_filter" value="<?php echo $name?>"/>
                        </p>
                        <p>
                            <input type="checkbox"  id="cb_dept_filter" name="cb_dept_filter" value="dept_filter" <?php if($cb_dept) echo 'checked';?>>  Search by Department<br/>
                            <!--<input type="text" id="dept_filter" name="dept_filter" value="<?php echo $dept?>"/>-->
                            <select id="dept_filter" name="dept_filter">
                                <?php
                                foreach($departments as $department) {
                                $selected = "";
                                if($dept == $department["DepartmentDescription"])
                                    $selected = "selected";
                                ?>
                                    <option value="<?= $department["DepartmentID"]?>" <?= $selected ?>><?= $department["DepartmentDescription"]?></option>;
                                <?php } ?>
                            </select>
                        </p>
                        <p>
                            <input type="checkbox" id="cb_spec_filter" name="cb_spec_filter" value="spec_filter"  <?php if($cb_spec) echo 'checked'; ?>> Search by Specialization<br/>
                            <input type="text" id="spec_filter" name="spec_filter" value="<?php echo $spec?>"/>
                        </p>

                        <p>
                            <br/>
                        <h4>Archive/Unarchived Search Filter</h4>
                        <input type="radio" name="rad_arch_filter" value="unarchive" <?php if($archive_search == 'unarchive') echo 'checked'; ?>/> Show Unarchived Only<br/>
                        <input type="radio" name="rad_arch_filter" value="archive" <?php if($archive_search == 'archive') echo 'checked'; ?>/> Show Archived Only<br/>
                        <input type="radio" name="rad_arch_filter" value="both" <?php if($archive_search == 'both' ) echo 'checked'; ?>/> Show Both<br/>
                        </p>
                    </div>
                    <button class="btn btn-primary" type="submit" id="btnSearch">Search</button>
                    <? echo form_close();?>
                    <!--</form>-->
                </div>
                <div class="col-lg-9">
                    <div class = 'search-results'>

                        <?php foreach($profiles as $profile){
                            $file = $base_url."images/fmis/members/".$profile['profileID']."/".$profile['profileID'].".jpg";

                            $file_headers = @get_headers($file);
                            if($file_headers[0] == 'HTTP/1.0 404 Not Found' || $file_headers[0] == 'HTTP/1.1 404 Not Found' ) {
                                $image = '<img class="img-responsive" alt="140x140" src="'.$base_url.'images/members/blank.png"/>';
                            }
                            else {
                                $image = '<img class="img-responsive" alt="140x140" src="'.$file.'"/>';
                            }

                            if($profile['profileStatus'] == 'Active')
                            {
                                $editStatus = 'Archive Profile';
                                $editStatusID = 2;
                            }
                            else
                            {
                                $editStatus = 'Un-archive Profile';
                                $editStatusID = 1;
                            }
                            ?>

                            <div id="profile<?= $profile['profileID'] ?>" class="search-result container-fluid">
                                <div class="container-fluid row">
                                    <div class="col-lg-3">
                                        <div class="image-holder">
                                            <?= $image?>
                                        </div>
                                    </div>
                                    <div class="col-lg-9">
                                        <div class="content-holder">
                                            <div class="details">
                                                <p class="firstname">First Name: <?= $profile['profileFirstName']?></p>
                                                <p class="middlename">Middle Name: <?= $profile['profileMiddleName']?></p>
                                                <p class="lastname">Last Name: <?= $profile['profileLastName']?></p>
                                                <p class="specialization">Specialization: <?= $profile['profileSpecialty']?></p>
                                                <p class="department">Department: <?= $profile['profileDept']?></p>
                                            </div>
                                            <div class="clear-both"></div>

                                        </div>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="control-holder">
                                        <a class="button button-primary" href="<?= $base_url?>fmis/faculty/profile/<?= $profile['profileID']?>">Go to Profile</a>
                                        <button class="button btnArchive btn-edit-status btnStatus" href="<?= $editStatusID?>"><?= $editStatus?></button>
                                        <button class="button btnPermission">Edit permissions</button>
                                        <button class="button btnPlantilla">Edit plantilla</button>
                                    </div>
                                </div>
                            </div>
                        <?php }?>

                        <!--<div id="profile1" class="search-result">
                                <div class="image-holder">
                                    <img alt="140x140" src="<?php echo $base_url?>img/members/1.jpg" />
                                </div>
                                <div class="content-holder">
                                    <div class="details">
                                        <p class="firstname">First Name: Richard</p>
                                        <p class="middlename">Middle Name: Barnagas</p>
                                        <p class="lastname">Last Name: Domingmondomniog</p>
                                        <p class="degree">Degree: heh</p>
                                        <p class="specialization">Specialization: asdfadf</p>
                                    </div>
                                    <div class="clear-both"></div>
                                    <div class="control-holder">
                                        <a class="btn btn-primary" href="#">Go to Profile</a>
                                        <a class="btn" href="#">Archive</a>
                                        <a class="btn" href="#">Edit permissions</a>
                                        <a class="btn" href="#">Edit plantilla</a>
                                    </div>
                                </div>
                            </div> -->
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<div id="archive-member" title="Edit Permission"></div>
<div id="dialog-sorry" title="Warning">
    <p>
        <span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span>Sadly, this functionality wasn't finished.
    </p>
</div>

<script type="text/javascript">
    $(function() {
        $( "#dialog-sorry" ).dialog({
            autoOpen: false,
            resizable: false,
            height:200,
            width: 300,
            modal: true,
            buttons: {
                Ok: function() {
                    $( this ).dialog( "close" );
                }
            }
        });

        if($('#cb_dept_filter').is(':checked'))
        {
            $("#dept_filter").prop("disabled", false);
        }
        else
        {
            $("#dept_filter").prop("disabled", true);
        }

        if($('#cb_spec_filter').is(':checked'))
        {
            $("#spec_filter").prop("disabled", false);
        }
        else
        {
            $("#spec_filter").prop("disabled", true);
        }

        if($('#cb_name_filter').is(':checked'))
        {
            $("#name_filter").prop("disabled", false);
        }
        else
        {
            $("#name_filter").prop("disabled", true);
        }

    });

    $('#btnSearch').on('click', function(e){
        //e.preventDefault();
    });

    $('.btnPlantilla').on('click', function(e){
        e.preventDefault();
        $( "#dialog-sorry" ).dialog('open');
    });

    $('.btnStatus').on('click', function(e){
        e.preventDefault();
        $( "#dialog-sorry" ).dialog('open')}
    );

    $('.btnPermission').on('click', function(e){
        e.preventDefault();
        $( "#dialog-sorry" ).dialog('open');
    });

    $("#cb_dept_filter").change( function(){
        if($(this).is(':checked'))
        {
            $("#dept_filter").prop("disabled", false);
        }
        else
        {
            $("#dept_filter").prop("disabled", true);
        }
    });

    $("#cb_spec_filter").change( function(){
        if($(this).is(':checked'))
        {
            $("#spec_filter").prop("disabled", false);
        }
        else
        {
            $("#spec_filter").prop("disabled", true);
        }
    });

    $("#cb_name_filter").change( function(){
        if($(this).is(':checked'))
        {
            $("#name_filter").prop("disabled", false);
        }
        else
        {
            $("#name_filter").prop("disabled", true);
        }
    });

</script>